package com.yangjiangtao.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
public class UploadController {

    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    @ResponseBody
    public String upload(@RequestParam("img") MultipartFile img) throws IOException {
        System.out.println("进来了！！！！！！！！！！！！！！！！");
        UUID uuid = UUID.randomUUID();
        String fileName = img.getOriginalFilename();
        int index = fileName.lastIndexOf(".");
        String newFileName = uuid+fileName.substring(index);
        img.transferTo(new File("C:\\Users\\18379\\Desktop\\" + newFileName));
        return "success";
    }

}
